// pages/classify/classify.js
Page({
  data: {
    currentCategory: 0,
    categories: ['全部', '指定大红', '顶级挑战', '趣味单', '护航专区', '指定大红单', '绝密赌约单', '顶级挑战单'],
    allProducts: {
      0: [ // 全部
        {
          id: 1,
          image: 'https://mpfile.shifoukeji.com/images/1758787804166-8023617087828925.jpg?image_process=resize,l_300',
          title: '猛I攻单',
          subtitle: '',
          price: 333,
          sales: 694
        },
        {
          id: 2,
          image: 'https://mpfile.shifoukeji.com/images/1758787804166-8023617087828925.jpg?image_process=resize,l_300',
          title: '暴走乌鸦兽',
          subtitle: '升级版',
          price: 788,
          sales: 2135
        },
        {
          id: 3,
          image: 'https://mpfile.shifoukeji.com/images/1758787804166-8023617087828925.jpg?image_process=resize,l_300',
          title: '塔桥单',
          subtitle: '',
          price: 333,
          sales: 897
        },
        {
          id: 4,
          image: 'https://mpfile.shifoukeji.com/images/1758787804166-8023617087828925.jpg?image_process=resize,l_300',
          title: '塔桥单',
          subtitle: '升级版',
          price: 788,
          sales: 964
        },
        {
          id: 5,
          image: 'https://mpfile.shifoukeji.com/images/1758787804166-8023617087828925.jpg?image_process=resize,l_300',
          title: '猎奇猎偶',
          subtitle: '',
          price: 388,
          sales: 1264
        },
        {
          id: 6,
          image: 'https://mpfile.shifoukeji.com/images/1758787804166-8023617087828925.jpg?image_process=resize,l_300',
          title: '"樱花口音"',
          subtitle: '',
          price: 248,
          sales: 743
        },
        {
          id: 6,
          image: 'https://mpfile.shifoukeji.com/images/1758787804166-8023617087828925.jpg?image_process=resize,l_300',
          title: '"樱花口音"',
          subtitle: '',
          price: 248,
          sales: 743
        },
        {
          id: 6,
          image: 'https://mpfile.shifoukeji.com/images/1758787804166-8023617087828925.jpg?image_process=resize,l_300',
          title: '"樱花口音"',
          subtitle: '',
          price: 248,
          sales: 743
        },
        {
          id: 6,
          image: 'https://mpfile.shifoukeji.com/images/1758787804166-8023617087828925.jpg?image_process=resize,l_300',
          title: '"樱花口音"',
          subtitle: '',
          price: 248,
          sales: 743
        },
        {
          id: 6,
          image: 'https://mpfile.shifoukeji.com/images/1758787804166-8023617087828925.jpg?image_process=resize,l_300',
          title: '"樱花口音"',
          subtitle: '',
          price: 248,
          sales: 743
        },
        {
          id: 6,
          image: 'https://mpfile.shifoukeji.com/images/1758787804166-8023617087828925.jpg?image_process=resize,l_300',
          title: '"樱花口音"',
          subtitle: '',
          price: 248,
          sales: 743
        },
        {
          id: 6,
          image: 'https://mpfile.shifoukeji.com/images/1758787804166-8023617087828925.jpg?image_process=resize,l_300',
          title: '"樱花口音"',
          subtitle: '',
          price: 248,
          sales: 743
        }
      ],
      1: [ // 指定大红
        {
          id: 11,
          image: 'https://mpfile.shifoukeji.com/images/1758787804166-8023617087828925.jpg?image_process=resize,l_300',
          title: '指定大红专属',
          subtitle: '高级版',
          price: 588,
          sales: 1200
        }
      ],
      2: [ // 顶级挑战
        {
          id: 21,
          image: 'https://mpfile.shifoukeji.com/images/1758787804166-8023617087828925.jpg?image_process=resize,l_300',
          title: '顶级挑战赛',
          subtitle: '专业版',
          price: 888,
          sales: 800
        }
      ],
      3: [ // 趣味单
        {
          id: 31,
          image: 'https://mpfile.shifoukeji.com/images/1758787804166-8023617087828925.jpg?image_process=resize,l_300',
          title: '塔桥单',
          subtitle: '',
          price: 333,
          sales: 897
        }
      ],
      4: [ // 护航专区
        {
          id: 41,
          image: 'https://mpfile.shifoukeji.com/images/1758787804166-8023617087828925.jpg?image_process=resize,l_300',
          title: '护航服务',
          subtitle: '安全保障',
          price: 199,
          sales: 1500
        }
      ],
      5: [ // 指定大红单
        {
          id: 51,
          image: 'https://mpfile.shifoukeji.com/images/1758787804166-8023617087828925.jpg?image_process=resize,l_300',
          title: '塔桥单',
          subtitle: '升级版',
          price: 788,
          sales: 964
        }
      ],
      6: [ // 绝密赌约单
        {
          id: 61,
          image: 'https://mpfile.shifoukeji.com/images/1758787804166-8023617087828925.jpg?image_process=resize,l_300',
          title: '绝密赌约',
          subtitle: '限量版',
          price: 999,
          sales: 500
        }
      ],
      7: [ // 顶级挑战单
        {
          id: 71,
          image: 'https://mpfile.shifoukeji.com/images/1758787804166-8023617087828925.jpg?image_process=resize,l_300',
          title: '猎奇猎偶',
          subtitle: '',
          price: 388,
          sales: 1264
        }
      ]
    },
    productList: [],
    // 底部导航图标 - 使用内嵌SVG图标
    navIcons: {
      home: '',
      category: '',
      order: '',
      profile: ''
    },
  },

  onLoad: function (options) {
    // 初始化显示全部商品
    this.setData({
      productList: this.data.allProducts[0]
    });
  },

  // 选择分类
  selectCategory: function (e) {
    const index = parseInt(e.currentTarget.dataset.index);
    console.log('选择分类:', index);
    this.setData({
      currentCategory: index,
      productList: this.data.allProducts[index] || []
    });
    console.log('当前分类:', this.data.currentCategory);
  },

  // 跳转到商品详情
  goToDetail: function (e) {
    const id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '/pages/goodDetails/goodDetails?id=' + id
    });
  },

  // 底部导航点击
  onNavTap(e) {
    const navType = e.currentTarget.dataset.type;
    switch (navType) {
      case 'home':
       wx.reLaunch({
        url: '/pages/index/index',
      })
        break;
      case 'category':
        wx.reLaunch({
          url: '/pages/classify/classify',
        })
        break;
      case 'order':
        wx.reLaunch({
          url: '/pages/orderList/orderList',
        })
        break;
      case 'profile':
        wx.reLaunch({
          url: '/pages/user/user',
        })
        break;
    }
  }
});